
export type UserInfo = {
    id: string;
    name: string
    account: string;
    email: string;
    avatar: string;
    rolas: Role[];
};

interface Role {
    roleId:string,
    roleName:string
}

//localStorage 的 key
const localKey = {
    token: 'USER_TOKEN',
    userInfo: 'USER_INFO',
    keepConnection: 'KEEP_CONNECTION'
}

const header = 'logintoken'

export enum FileType{
    USER_AVATAR = "USER_AVATAR",
    OTHER = "OTHER",
    SHOW = "SHOW"
}

const userInfo: ()=> UserInfo = () => {
    const userStr: string | null = localStorage.getItem(localKey.userInfo);
    if (userStr != null) {
        return  JSON.parse(userStr);
    }
}



const clear = () => {
    localStorage.removeItem(localKey.token)
    localStorage.removeItem(localKey.userInfo)
    localStorage.removeItem(localKey.keepConnection)
}

const save = (token:string,userInfo:string,keepConnection:string) => {
    localStorage.setItem(localKey.token, token)
    localStorage.setItem(localKey.userInfo, userInfo)
    localStorage.setItem(localKey.keepConnection, keepConnection)
}

export {localKey, header, clear, save, userInfo};